/*
 * Copyright (c) 2007 The Chai Team
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

package com.google.projects.chai.data;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Represents a user of our system.
 * @author dap
 */
public class User {
        /* Authentication data */
        private int UserId;
        
        /** 
         * The unique username, which can be used to login and by which people
         * can search for their friends.
         */
        private String Username;
        /** 
         * The primary email address for this account. This should change later 
         * to a list of EmailAddress records, one of which is Primary.
         */
        private String PrimaryEmail;
        /**
         * The hashed version of the login password.
         */
        private String PasswordHash;
        /**
         * The account activation confirmation string (used for inactive users)
         */
        private String ConfirmationHash;
        
        /* Identifying information */
        /** Location, by which people can search for other people */
        private String Location;
        
        /* Application-related information */
        /** A list of contact groups, indexed by name */
        private Set<UserGroup> Groups = new HashSet<UserGroup>();
 
        /** A name to be displayed publicly */
        private String DisplayName;
        
        /** A real name (by which one can be searched) */
        private String RealName;
                
        /**
         * True if this account is activated. An account begins inactive, and is
         * activated when the user clicks the link in the confirmation email.
         * (This also confirms the email address.) While an account is inactive,
         * the user cannot login.
         * <p>
         * When the user has their password reset, their account is deactivated.
         * The sign-up process is repeated (they get an email with a code which
         * reactivates their account).
         */
        private boolean Active;

        /* Useful methods */
        public int getUserIdentifier() {
                return UserId;
        }
        
        /* Accessors */

        public int getUserId() {
                return UserId;
        }

        private void setUserId(int UserId) {
                this.UserId = UserId;
        }

        public String getUsername() {
                return Username;
        }

        public void setUsername(String Username) {
                this.Username = Username;
        }

        public String getPrimaryEmail() {
                return PrimaryEmail;
        }

        public void setPrimaryEmail(String PrimaryEmail) {
                this.PrimaryEmail = PrimaryEmail;
        }

        public String getPasswordHash() {
                return PasswordHash;
        }

        public void setPasswordHash(String PasswordHash) {
                this.PasswordHash = PasswordHash;
        }

        public String getLocation() {
                return Location;
        }

        public void setLocation(String Location) {
                this.Location = Location;
        }

        public Set<UserGroup> getGroups() {
                return Groups;
        }

        public void setGroups(Set<UserGroup> Groups) {
                this.Groups = Groups;
        }

        public String getDisplayName() {
                return DisplayName;
        }

        public void setDisplayName(String DisplayName) {
                this.DisplayName = DisplayName;
        }

        public String getRealName() {
                return RealName;
        }

        public void setRealName(String RealName) {
                this.RealName = RealName;
        }

        public boolean getActive() {
                return Active;
        }

        public void setActive(boolean Active) {
                this.Active = Active;
        }

        public String getConfirmationHash() {
                return ConfirmationHash;
        }

        public void setConfirmationHash(String ConfirmationHash) {
                this.ConfirmationHash = ConfirmationHash;
        }
        
        public Map<String, String> getPropertyMap() {
                Map<String, String> props = new HashMap<String, String>();
                props.put("DisplayName", DisplayName);
                props.put("Location", Location);
                props.put("PrimaryEmail", PrimaryEmail);
                props.put("RealName", RealName);
                props.put("UserId", String.valueOf(UserId));
                props.put("Username", Username);
                return Collections.unmodifiableMap(props);
        }

}
